import { Method } from "axios";
import { ref } from 'vue'
import useRequet, { RespData } from "./network"
import { ElMessage } from 'element-plus'
import { InterFaceType } from '../types/index'

export default function useRequest(path: string, params: any, method: Method) {
  const request = useRequet({ path })
  return new Promise((resolve, reject) => {
    request.sendRequest({
      address: '',
      params,
      success: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error(resp.msg)
        // let data = resp.data
        resolve(resp)
      },
      fail: (resp: RespData) => {
        if(resp.code !== 0) return ElMessage.error(resp.msg)
        console.log(resp)
        reject(resp)
      },
      method
    })
  })
}